home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / PRGrRef.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  2.1 KB  |  96 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                PRGrRef.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef PRGRREF_H
  11. #define PRGRREF_H
  12.  
  13. //========================================================================================
  14. //    class FW_CPrivGrRefObj
  15. //========================================================================================
  16.  
  17. class FW_CPrivGrRefObj
  18. {
  19. public:
  20.     FW_CPrivGrRefObj();
  21.     virtual ~FW_CPrivGrRefObj();
  22.     
  23.     void        Acquire()
  24.         { ++ fRefCount; }
  25.     void        Release();
  26.     long        GetRefCount()
  27.         { return fRefCount; }
  28.  
  29. private:
  30.     long        fRefCount;
  31. };
  32.  
  33. //========================================================================================
  34. //    class FW_CPrivGrRefPtrBase
  35. //========================================================================================
  36.  
  37. class FW_CPrivGrRefPtrBase
  38. {
  39. public:
  40.     FW_DECLARE_AUTO(FW_CPrivGrRefPtrBase)
  41.     ~FW_CPrivGrRefPtrBase();
  42.  
  43. protected:
  44.     FW_CPrivGrRefPtrBase();
  45.  
  46.     FW_CPrivGrRefPtrBase(FW_CPrivGrRefObj* rep);
  47.     
  48.     void    SetRep(FW_CPrivGrRefObj* rep);
  49.  
  50.     FW_CPrivGrRefObj*        fRep;
  51. };
  52.  
  53. //========================================================================================
  54. //    class FW_CPrivGrRefPtr
  55. //========================================================================================
  56.  
  57. template <class T>
  58. class FW_CPrivGrRefPtr : private FW_CPrivGrRefPtrBase
  59. {
  60. public:
  61.  
  62.     FW_CPrivGrRefPtr()
  63.         { }
  64.  
  65.     FW_CPrivGrRefPtr(T* rep) :
  66.         FW_CPrivGrRefPtrBase(rep)
  67.         { }
  68.     
  69.     FW_CPrivGrRefPtr(const FW_CPrivGrRefPtr<T>& other) :
  70.         FW_CPrivGrRefPtrBase(other.fRep)
  71.         { }
  72.  
  73.     FW_Boolean IsSameRepAs(const FW_CPrivGrRefPtr<T>& other) const
  74.         { return fRep == other.fRep; }
  75.  
  76.     void operator=(const FW_CPrivGrRefPtr<T>& other)
  77.         { SetRep(other.fRep); }
  78.         
  79.     void operator=(T* rep)
  80.         { SetRep(rep); }
  81.  
  82.     T*        operator->()
  83.         { return (T*) fRep; }
  84.  
  85.     const T* operator->() const
  86.         { return (const T*) fRep; }
  87.  
  88.     operator T*()
  89.         { return (T*) fRep; }
  90.  
  91.     operator const T*() const
  92.         { return (const T*) fRep; }
  93. };
  94.  
  95. #endif // PRGRREF_H
  96.